#include "curl_ftp_upload.h"
#include <iostream>
#include "thread_pool.hpp"

static const char* ip = "10.40.27.82";
static const char* username = "admin";
static const char* passwd = "iflytek";

int test1()
{
    int ret = easy_init(ip, username, passwd);
    if (0 == ret)
    {
        char remotepath[] = "aa/MicrosoftOffice2016.zip";
        char localpath[] = "C:/test/MicrosoftOffice2016.zip";
        ret = upload_file(remotepath, localpath);
    }

    easy_cleanup();
    return ret;
}

int test2()
{
    int ret = easy_init(ip, username, passwd);
    if (0 == ret) 
    {
        char remotepath[] = "bb/MicrosoftOffice2016.zip";
        char localpath[] = "C:/test/MicrosoftOffice2016.zip";
        ret = upload_file(remotepath, localpath);
    }

    easy_cleanup();
    return ret;
}

int test3()
{
    int ret = easy_init(ip, username, passwd);
    if (0 == ret)
    {
        char remotepath[] = "cc/MicrosoftOffice2016.zip";
        char localpath[] = "C:/test/MicrosoftOffice2016.zip";
        ret = upload_file(remotepath, localpath);
    }

    easy_cleanup();
    return ret;
}

int test4()
{
    int ret = easy_init(ip, username, passwd);
    if (0 == ret)
    {
        char remotepath[] = "dd/MicrosoftOffice2016.zip";
        char localpath[] = "C:/test/MicrosoftOffice2016.zip";
        ret = upload_file(remotepath, localpath);
    }

    easy_cleanup();
    return ret;
}

int test5()
{
    int ret = easy_init(ip, username, "iflytek");
    {
        char remotepath1[] = "aa/MicrosoftOffice2016.zip";
        char remotepath2[] = "bb/MicrosoftOffice2016.zip";
        char remotepath3[] = "cc/MicrosoftOffice2016.zip";
        char remotepath4[] = "dd/MicrosoftOffice2016.zip";
        char localpath[] = "C:/test/MicrosoftOffice2016.zip";
        ret = upload_file(remotepath1, localpath);
        if (0 != ret)
            return ret;

        ret = upload_file(remotepath2, localpath);
        if (0 != ret)
            return ret;

        ret = upload_file(remotepath3, localpath);
        if (0 != ret)
            return ret;

        ret = upload_file(remotepath4, localpath);
        if (0 != ret)
            return ret;
    }

    easy_cleanup();
    return ret;
}


int main(void)
{
    global_init();
    // create thread pool with 4 worker threads
    ThreadPool pool(5);

    // enqueue and store future
    auto ret1 = pool.enqueue(test1);
    auto ret2 = pool.enqueue(test2);
    auto ret3 = pool.enqueue(test3);
    auto ret4 = pool.enqueue(test4);
    auto ret5 = pool.enqueue(test5);

    // get result from future
    std::cout << "ret1.get(): " << ret1.get() << std::endl;
    std::cout << "ret2.get(): " << ret2.get() << std::endl;
    std::cout << "ret3.get(): " << ret3.get() << std::endl;
    std::cout << "ret4.get(): " << ret4.get() << std::endl;

    char c(' ');

    while (c != 'q' && c != 'Q')
    {
        std::cout << "Press q then enter to quit: \n";
        std::cin >> c;
    }
    global_cleanup();
    return 0;
}






